cmake_minimum_required(VERSION 2.8)
project(FAN_LLVM C CXX)

# Find the dependencies
SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR})
find_package(ZLIB REQUIRED)
find_package(ICU REQUIRED)
find_package(LLVM REQUIRED)

# Detect and normalize the OS name
string(TOLOWER ${CMAKE_SYSTEM_NAME} FAN_SYSTEM_NAME)
if(FAN_SYSTEM_NAME STREQUAL "windows")
  set(FAN_SYSTEM_NAME "win32")
elseif(FAN_SYSTEM_NAME STREQUAL "darwin")
  set(FAN_SYSTEM_NAME "macosx")
elseif(FAN_SYSTEM_NAME STREQUAL "sunos")
  set(FAN_SYSTEM_NAME "solaris")
endif()

# Detect and normalize the CPU arch
string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} FAN_SYSTEM_ARCH)
if((FAN_SYSTEM_ARCH STREQUAL "i386") OR
   (FAN_SYSTEM_ARCH STREQUAL "i486") OR
   (FAN_SYSTEM_ARCH STREQUAL "i586") OR
   (FAN_SYSTEM_ARCH STREQUAL "i686"))
  set(FAN_SYSTEM_ARCH "x86")
elseif(FAN_SYSTEM_ARCH STREQUAL "amd64")
  set(FAN_SYSTEM_ARCH "ia64")
endif()

# Generate config.h with the platform-specific values
configure_file("config.h.in" "config.h" @ONLY)

# Set the compilation flags and include-directories
set(CMAKE_C_FLAGS "-std=c99 -Wall")
set(CMAKE_C_FLAGS_DEBUG "-g")
set(CMAKE_C_FLAGS_RELEASE "-03")
set(CMAKE_CXX_FLAGS "-Wall ${LLVM_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-03")
set(CMAKE_INCLUDE_CURRENT_DIR YES)
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/..)
include_directories(SYSTEM ${ZLIB_INCLUDE_DIRS})
include_directories(SYSTEM ${ICU_INCLUDE_DIRS})

# Define the directories to build
add_subdirectory("core")
add_subdirectory("pods/sys")
#add_subdirectory("runtime")
add_subdirectory("tests")
